package com.LeeCode;

import java.util.Arrays;

/**
 * 你能在你最喜欢的那天吃到你最喜欢的糖果吗？
 */

public class Code1744 {
    public static void main(String[] args) {
        int[] candiesCount = {7, 4, 5, 3, 8};
        int[][] queries = {{0, 2, 2}, {4, 2, 4}, {2, 13, 1000000000}};
        System.out.println(Arrays.toString(new Code1744().canEat(candiesCount, queries)));
    }

    public boolean[] canEat(int[] candiesCount, int[][] queries) {

        long[] prevSum = new long[candiesCount.length + 1];
        for (int i = 0; i < candiesCount.length; i++) {
            prevSum[i + 1] = prevSum[i] + candiesCount[i];
        }

        boolean[] ans = new boolean[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int type = queries[i][0], day = queries[i][1] + 1, count = queries[i][2];
            if (day > prevSum[type + 1] || ((long) day * count) <= prevSum[type]) { // 吃完了或者吃不到
                continue;
            }
            ans[i] = true;
        }
        return ans;
    }
}
